let { imgUrl } = getApp().globalData;
Page({
  data: {
    imgUrl: `${imgUrl}/applet_web_images/new_image`,
    iPhone15: [
      {
        id: "100698",
        img: "/member/iPhone15/15Pro.png",
      },
      {
        id: "100699",
        img: "/member/iPhone15/15Plus.png",
      },
      {
        id: "100700",
        img: "/member/iPhone15/iPhone15.png",
      },
    ],
    iPhone14: [
      {
        id: "100696",
        img: "/member/iPhone14/14Pro.png",
      },
      {
        id: "100476",
        img: "/member/iPhone14/14Plus.png",
      },
      {
        id: "100475",
        img: "/member/iPhone14/iPhone14.png",
      },
    ],
    // 热门推荐
    hotRecommend: [
      {
        id: "100333",
        img: "/member/hot_recommend/13ProMax.png",
      },
      {
        id: "100164",
        img: "/member/hot_recommend/13Pro.png",
      },
      {
        id: "100440",
        img: "/member/hot_recommend/iPhone13.png",
      },
      {
        id: "100565",
        img: "/member/hot_recommend/asus4.png",
      },
      {
        id: "100566",
        img: "/member/hot_recommend/asus4Plus.png",
      },
      {
        id: "100564",
        img: "/member/hot_recommend/asus3.png",
      },
    ],
    couponList: [],
    visible: false, // 弹窗开启
    animation: true,
  },
  onLoad(options) {
    const app = getApp();
    const { platform } = options; // 有会员参数
    if (platform) {
      app.globalData.platform = platform
      app.getAuth_base(() => {})
    }
  },
  // 订阅消息
  subscribeMessage() {
    my.requestSubscribeMessage({
      entityIds: [
        "b0c7589d65dd4352922e1b6016f0a78d",
        "1ad56d038bfe4bfabe91db8dfd703ce5",
        "366afcf17f424cf0b8d67a93493bae7a",
      ],
      success: () => {},
      fail: () => {},
    });
  },

  onClose() {
    this.collectVouchers();
  },
  handlePopupClose() {
    this.setData({
      visible: false,
    });
  },
  // 使用说明
  getIshow(e) {
    const index = e.target.dataset.index;
    const isShow = this.data.couponList[index].isShow;
    let _isShow = "couponList[" + index + "].isShow";
    this.setData({
      [_isShow]: !isShow,
    });
  },

  // 领优惠券
  collectVouchers() {
    const app = getApp();
    this.setData({
      visible: true,
    });
    my.showLoading({
      content: "加载中",
    });
    app.getAuth_base((zm_user_id) => {
      const { testUrl } = app.globalData;

      my.request({
        url: `${testUrl}/api/voucher/receiveVoucherCenter`,
        method: "POST",
        data: {
          zm_user_id,
        },
        dataType: "json",
        success: (res) => {
          const { data: list, code, msg: content } = res.data;
          if (code !== 1) {
            my.showToast({
              type: "none",
              content,
            });
            return;
          }
          const couponList = list.map((item, index) => {
            item.uuid = `${new Date().getTime()}${index}`;
            return item;
          });
          this.setData({
            couponList,
          });
        },
        complete: () => {
          my.hideLoading();
        },
      });
    });
  },
  addGroup() {
    my.ap.openURL({
      url: "alipays://platformapi/startapp?appId=68687451&url=%2Fwww%2Fbc-join.html%3Foid%3D2023020316330500021149%26businessId%3D2023020316330500021149%26businessType%3D18%26source%3DOTHERS",
    });
  },
  jumpDetail(e) {
    const { id } = e.target.dataset;
    my.navigateTo({
      url: `/page/rent/goodsdetail/goodsdetail?id=${id}`,
    });
  },
  returnHome() {
    my.switchTab({
      url: "/page/rent/rent",
    });
  },
});
